<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">

    <title>车位管理</title>
    <meta charset="UTF-8">
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">

    <!--  easyui.css  -->
    <link rel="stylesheet" type="text/css" href="css/easyui/themes/default/easyui.css">
    <!--  icon.css  -->
    <link rel="stylesheet" type="text/css" href="css/easyui/themes/icon.css">
    <!--  color.css  -->
    <link rel="stylesheet" type="text/css" href="css/easyui/themes/color.css">
    <!--  demo.css  -->
    <link rel="stylesheet" type="text/css" href="css/easyui/demo/demo.css">
    <!--  jquery-1.6.min.js -->
    <script type="text/javascript" src="js/jquery/1.6/jquery-1.6.min.js"></script>
    <!--  jquery.easyui.min.js  -->
    <script type="text/javascript" src="js/easyui/1.4/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="js/easyui/1.4/easyui-lang-zh_CN.js"></script>
    <style type="text/css">
        #fm{
            margin:0;
            padding:10px 30px;
        }
        .ftitle{
            font-size:14px;
            font-weight:bold;
            padding:5px 0;
            margin-bottom:10px;
            border-bottom:1px solid #ccc;
        }
        .fitem{
            margin-bottom:5px;
        }
        .fitem label{
            display:inline-block;
            width:80px;
        }
        .fitem input{
            width:160px;
        }
    </style>
  </head>
  <body>
    <div class="easyui-panel" title="网点信息" style="width:700px">
        <div style="padding:10px 60px 20px 60px">
            <table cellpadding="5">
                <tr>
                    <td>网点名称:</td>
                    <td>测试网点</td>
                </tr>
                <tr>
                    <td>网点地址：</td>
                    <td>福建厦门市软件园二期观日路二号楼</td>
                </tr>
                <tr> 
                    <td>网点车位数量（个）</td>
                    <td>测试</td>
                </tr>
                <tr>
                    <td>网点营业起止时间</td>
                    <td>08：00 - 20：00</td>
                </tr>
            </table>
        </div>
    </div>
    <table id="dg" title="网点车位信息" class="easyui-datagrid" style="width:700px;height:450px"
            url="admin/getParkByNetworkId/${netWork.networkId}.do"
            toolbar="#toolbar" pagination="true"
            rownumbers="true" fitColumns="true" singleSelect="true">
        <thead>
            <tr>
                <th field="parkId" width="50">车位id</th>
                <th field="parkName" width="50">车位名称</th>
                <th field="parkSize" width="50">车位大小</th>
                <th field="parkPrice" width="100">充电车位每小时单价（元/小时）</th>
            </tr>
        </thead>
    </table>
    <div id="toolbar">
        <br/>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newPark()">添加车位</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editPark()">编辑车位</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyPark()">删除车位</a>
    </div>

    
    <!-- easyui-dialog -->
    <div id="dlg" class="easyui-dialog" style="width:500px;height:400px;padding:10px 20px"
            closed="true" buttons="#dlg-buttons">
        <div class="ftitle">车位添加</div>
        <form id="fm" method="post" novalidate>
            <div class="fitem" style="display: none">
                <label>车位Id</label>
                <input name="parkId" class="easyui-textbox">
            </div>
            <div class="fitem">
                <label>车位名称</label>
                <input name="parkName" class="easyui-textbox">
            </div>
            <div class="fitem">
                <label>车位大小</label>
                <input name="parkSize" class="easyui-textbox">
            </div>
            <div class="fitem">
                <label>单价（元/小时）</label>
                <input name="parkPrice" class="easyui-textbox">
            </div>
        </form>
    </div>
    <div id="dlg-buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="saveUser()" style="width:90px">Save</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">Cancel</a>
    </div>

  </body>
  <script type="text/javascript">
        var url;
        function newPark(){
            $('#dlg').dialog('open').dialog('center').dialog('setTitle','创建车位');
            $('#fm').form('clear');
            url = 'admin/saveParkByNetWorkId/${netWork.networkId}.do';
        }
        function editPark(){
            var row = $('#dg').datagrid('getSelected');
            if (row){
                $('#dlg').dialog('open').dialog('center').dialog('setTitle','Edit User');
                $('#fm').form('load',row);
                url = 'admin/ajax_modify_park.do';
            }
        }

        function saveUser(){
            $('#fm').form('submit',{
                url: url,
                onSubmit: function(){
                    return $(this).form('validate');
                },
                success: function(data){
                	
                	var result =  eval('(' + data + ')');
                    if (result.errorMsg != ''){
                        $.messager.show({
                            title: 'Error',
                            msg: result.errorMsg
                        });
                    } else {
                        $('#dlg').dialog('close');        // close the dialog
                        $('#dg').datagrid('reload');    // reload the user data
                    }
                }
            });
        }

        function destroyPark(){
            var row = $('#dg').datagrid('getSelected');
            if (row){
                $.messager.confirm('Confirm','请问你确定要删除这个车位',function(r){
                    if (r){
                        $.post('admin/ajax_delete_park.do',{parkId:row.parkId},function(result){
		                     if (result.flg) {
                                $.messager.alert('成功提示','成功删除网点（'+row.parkName+'）','info');
                                $('#dg').datagrid('reload'); // reload the user data
                            } else {
                                $.messager.show( { // show error message
                                            title : 'Error',
                                            msg : result.errorMsg
                                        });
                            }
                        },'json');
                    }
                });
               
            }
        }
    </script>
</html>
